package com.linked.mystyle.statement.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.linked.mystyle.statement.bean.param.StatementPageParam;
import com.linked.mystyle.statement.bean.po.StatementInfoPO;
import com.linked.mystyle.statement.service.IStatementService;
import com.linked.universal.common.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author :dbq
 * @date : 2022/10/17 15:29
 */
@RestController
@RequestMapping("statement")
public class StatementController {

    private final static Logger logger = LoggerFactory.getLogger(StatementController.class);
    private final IStatementService statementService;

    @Autowired
    public StatementController(IStatementService statementService) {
        this.statementService = statementService;
    }

    @PostMapping("saveStatement")
    public Result saveStatement(@RequestBody StatementInfoPO param) {
        Boolean ret = null;
        try {
            ret = statementService.saveStatement(param);
        } catch (Exception e) {
            logger.error("保存账单接口异常", e);
            return Result.error();
        }
        return ret ? Result.ok(true, "保存账单成功！") : Result.ok(false, "保存账单失败！");
    }

    @PostMapping("queryStatementPage")
    Result queryStatementPage(@RequestBody StatementPageParam param) {

        IPage<StatementInfoPO> ret = null;
        try {
            ret = statementService.queryStatementPage(param);
        } catch (Exception e) {
            logger.error("查询账单页面接口异常", e);
            return Result.error("查询账单页面接口异常");
        }
        return Result.success(ret);
    }

    @PostMapping("updateStatement")
    Result updateStatement(@RequestBody StatementInfoPO param) {
        Boolean ret = false;
        try {
            ret = statementService.updateStatement(param);
        } catch (Exception e) {
            logger.error("修改账单接口异常", e);
            return Result.error("修改账单接口异常");
        }
        return ret ? Result.ok(true, "修改账单成功") : Result.ok(false, "修改账单失败");
    }
}
